<template>
  <view>
    <!-- 信封条 -->
    <view
      style="
        width: 98%;
        height: 20upx;
        background-color: #028a9e;
        position: fixed;
        margin: 0 1% 0;
        z-index: 2;
        box-sizing: border-box;
        border-radius: 6upx;
      "
      class="spc"
    ></view>
    <view class="letter-box" :class="{ close: isCloseLetter }" id="lebox">
      <view>
        <slot name="content"></slot>
      </view>
      <view class="closeBtn flex flex-al-c" @tap="closeLetter">
        <view class="iconfont">{{
          isCloseLetter ? "&#xe6f0;" : "&#xe60f;"
        }}</view
        >{{ isCloseLetter ? "展开" : "收起" }}
      </view>
    </view>

    <view
      :style="{ height: isCloseLetter ? '40upx' : atHeight + 'px' }"
      class="animate"
    ></view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      isCloseLetter: false,
      atHeight: "",
      oldHeight: 20,
      tapLetter: false,
    };
  },
  updated() {
    const query = uni.createSelectorQuery().in(this);
    query
      .select("#lebox")
      .boundingClientRect((data) => {
        this.atHeight = data.height;
        this.$store.state.heights = data.height;
      })
      .exec();
  },
  methods: {
    closeLetter() {
      this.tapLetter = true;
      this.isCloseLetter = !this.isCloseLetter;
      const idx = this.isCloseLetter;
    },
    pclose(bool) {
      if (this.tapLetter) {
        this.tapLetter = false;
        return;
      }
      this.isCloseLetter = bool;
    },
  },
};
</script>

<style lang="less" scoped>
//  信封
.animate {
  transition: height 0.2s ease-out;
}
.letter-box {
  width: 96%;
  margin: 10upx 2% 0;
  position: fixed;
  overflow-y: hidden;
  // height: 600upx;
  background-color: #fff;
  box-shadow: 0 0 30upx 0 #ccc;
  border-bottom-left-radius: 10upx;
  border-bottom-right-radius: 10upx;
  transition: height 0.2s linear;
  z-index: 2;
}
.letter-box.close {
  height: 40upx;
}
.letter-list {
  position: absolute;
  width: 100%;
  bottom: 30upx;
  left: 0;
  bottom: 50upx;
  flex-wrap: wrap;
  .letter-item {
    width: 30%;
    text-align: center;
    padding: 30upx 0;
    .icon {
      width: 50upx;
      height: 50upx;
    }
    .tit {
      font-size: 24upx;
    }
  }
}
.closeBtn {
  position: absolute;
  width: 100%;
  left: 0;
  bottom: 0;
  font-size: 24upx;
  color: #ccc;
  justify-content: center;
}
</style>
<style scoped>
@media (prefers-color-scheme: closedark) {
  //  黑暗模式
  * {
    // background-color: #000000 !important;
    color: #ffffff !important;
  }
  .head {
    background-color: #2a2a2c !important;
  }
  .spc {
    background-color: #2a2a2c !important;
  }
  //信封条
  .spd {
    background-color: #1b1c1e !important;
  }
}
</style>
